package org.demo.filemanager.widget.filesystem;

import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

import org.boxlayout.gui.BoxLayoutEngine;
import org.boxlayout.gui.MouseCustomable;
import org.boxlayout.gui.VisualElement;
import org.boxlayout.gui.type.ColorEnum;
import org.boxlayout.gui.widget.TreeBrowsable;

public class ImageFileWidget extends FileWidget {

	MouseCustomable imageBehaviour ;
	
	public ImageFileWidget(BoxLayoutEngine ble, String path) {
		super(ble, path);		
	}
	
	@Override
	public TreeBrowsable initVisual() {
		super.initVisual();
		nameContainer.setMouseReleasedListener(new MouseCustomable() {
			public void onEvent(MouseEvent event) {		
				setExpanded(!expanded);
				//selector.select(me);
			}
		});
		return this;
	}
	
	@Override
	public void setExpanded(Boolean expand){
		if (!expanded && expand) {
			System.out.println("expand");
			VisualElement newImageElement = ble.createElement();
			newImageElement.setImage(path);
			newImageElement.setColor(ColorEnum.PINK);
			if (imageElement == null) {
				imageElement = newImageElement;
				visual.add(imageElement);
			} else {
				visual.replace(imageElement, newImageElement);
			}
			imageElement.setEnable(true);
			ble.reLayout();
		} else if (expanded && !expand) {
			System.out.println("collapse");
			imageElement.setEnable(false);
			ble.reLayout();
		}
		expanded = expand;
	}
	
	public List<TreeBrowsable> getChilds() {
		return new ArrayList<TreeBrowsable>();//fileWidgetChilds;
	}

}
